package org.jetnuke.modules.blog;

import org.apache.log4j.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.BlogUserSettingsDAO;
import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.entities.BlogUserSettings;
import org.jetnuke.util.JetUtil;
import org.jetnuke.util.StringUtils;

public class UpdateUserSettings implements IAction {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger
			.getLogger(UpdateUserSettings.class);

	int max_number_posts;
	String title, description;
	String title1, title2, title3, title4, title5;
	String content1, content2, content3, content4, content5;

	public void setTitle1(String title1) {
		if (logger.isDebugEnabled()) {
			logger.debug("setTitle1(String) - start"); //$NON-NLS-1$
		}

		this.title1 = StringUtils.filterText(title1, true);

		if (logger.isDebugEnabled()) {
			logger.debug("setTitle1(String) - end"); //$NON-NLS-1$
		}
	}

	public void setTitle2(String title2) {
		if (logger.isDebugEnabled()) {
			logger.debug("setTitle2(String) - start"); //$NON-NLS-1$
		}

		this.title2 = StringUtils.filterText(title2, true);

		if (logger.isDebugEnabled()) {
			logger.debug("setTitle2(String) - end"); //$NON-NLS-1$
		}
	}

	public void setTitle3(String title3) {
		if (logger.isDebugEnabled()) {
			logger.debug("setTitle3(String) - start"); //$NON-NLS-1$
		}

		this.title3 = StringUtils.filterText(title3, true);

		if (logger.isDebugEnabled()) {
			logger.debug("setTitle3(String) - end"); //$NON-NLS-1$
		}
	}

	public void setTitle4(String title4) {
		if (logger.isDebugEnabled()) {
			logger.debug("setTitle4(String) - start"); //$NON-NLS-1$
		}

		this.title4 = StringUtils.filterText(title4, true);

		if (logger.isDebugEnabled()) {
			logger.debug("setTitle4(String) - end"); //$NON-NLS-1$
		}
	}

	public void setTitle5(String title5) {
		if (logger.isDebugEnabled()) {
			logger.debug("setTitle5(String) - start"); //$NON-NLS-1$
		}

		this.title5 = StringUtils.filterText(title5, true);

		if (logger.isDebugEnabled()) {
			logger.debug("setTitle5(String) - end"); //$NON-NLS-1$
		}
	}

	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {
		if (logger.isDebugEnabled()) {
			logger
					.debug("exec(HttpServletRequest, HttpServletResponse, VelocityContext, IModuleInfo, String, IUserInfo, IAdminInfo) - start"); //$NON-NLS-1$
		}

		if (ui == null || ui.getID() < 2)
			return null;
		BlogUserSettingsDAO busm = DataAccessDriver.getInst()
				.newBlogUserSettingsDAO();
		BlogUserSettings bus = busm.retrieveByPk(ui.getID());
		bus.setDESCRIPTION(description);
		bus.setMAXNUMBERPOST(max_number_posts);

		bus.setTITLE(title);
		bus.setBLOCKTITLE1(title1);
		bus.setBLOCKTITLE2(title2);
		bus.setBLOCKTITLE3(title3);
		bus.setBLOCKTITLE4(title4);
		bus.setBLOCKTITLE5(title5);
		bus.setBLOCKCONTENT1(content1);
		bus.setBLOCKCONTENT2(content2);
		bus.setBLOCKCONTENT3(content3);
		bus.setBLOCKCONTENT4(content4);
		bus.setBLOCKCONTENT5(content5);
		busm.update(bus);
		JetUtil.redirect(vc, response, request.getContextPath()
				+ "/do/blog/your_blog");

		if (logger.isDebugEnabled()) {
			logger
					.debug("exec(HttpServletRequest, HttpServletResponse, VelocityContext, IModuleInfo, String, IUserInfo, IAdminInfo) - end"); //$NON-NLS-1$
		}
		return null;
	}

	public void setDescription(String description) {
		if (logger.isDebugEnabled()) {
			logger.debug("setDescription(String) - start"); //$NON-NLS-1$
		}

		this.description = StringUtils.filterText(description, false);

		if (logger.isDebugEnabled()) {
			logger.debug("setDescription(String) - end"); //$NON-NLS-1$
		}
	}

	public void setMax_number_posts(int max_number_posts) {
		this.max_number_posts = max_number_posts;
	}

	public void setTitle(String title) {
		if (logger.isDebugEnabled()) {
			logger.debug("setTitle(String) - start"); //$NON-NLS-1$
		}

		this.title = StringUtils.filterText(title, true);

		if (logger.isDebugEnabled()) {
			logger.debug("setTitle(String) - end"); //$NON-NLS-1$
		}
	}

	public void setContent1(String content1) {
		if (logger.isDebugEnabled()) {
			logger.debug("setContent1(String) - start"); //$NON-NLS-1$
		}

		this.content1 = StringUtils.filterText(content1, false);

		if (logger.isDebugEnabled()) {
			logger.debug("setContent1(String) - end"); //$NON-NLS-1$
		}
	}

	public void setContent2(String content2) {
		if (logger.isDebugEnabled()) {
			logger.debug("setContent2(String) - start"); //$NON-NLS-1$
		}

		this.content2 = StringUtils.filterText(content2, false);

		if (logger.isDebugEnabled()) {
			logger.debug("setContent2(String) - end"); //$NON-NLS-1$
		}
	}

	public void setContent3(String content3) {
		if (logger.isDebugEnabled()) {
			logger.debug("setContent3(String) - start"); //$NON-NLS-1$
		}

		this.content3 = StringUtils.filterText(content3, false);

		if (logger.isDebugEnabled()) {
			logger.debug("setContent3(String) - end"); //$NON-NLS-1$
		}
	}

	public void setContent4(String content4) {
		if (logger.isDebugEnabled()) {
			logger.debug("setContent4(String) - start"); //$NON-NLS-1$
		}

		this.content4 = StringUtils.filterText(content4, false);

		if (logger.isDebugEnabled()) {
			logger.debug("setContent4(String) - end"); //$NON-NLS-1$
		}
	}

	public void setContent5(String content5) {
		if (logger.isDebugEnabled()) {
			logger.debug("setContent5(String) - start"); //$NON-NLS-1$
		}

		this.content5 = StringUtils.filterText(content5, false);

		if (logger.isDebugEnabled()) {
			logger.debug("setContent5(String) - end"); //$NON-NLS-1$
		}
	}

}
